<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 在构造函数外部去调用 resovle reject 的问题

      const { promise, resolve, reject } = Promise.withResolvers()

      function test() {
        resolve('ok') // reject 同理
      }
      test()

      promise.then(res => {
        console.log(res)
      })

      /**
			 * 新API 没出来之前的写法
      let res, rej
      const p = new Promise((resolve, reject) => {
        // resolve('ok')
        res = resolve
        rej = reject
      })

      function test() {
        res('ok')
      }
      test()

      p.then(res => {
        console.log(res)
      })
			**/
    </script>
  </body>
</html>
